#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
using namespace std;

int main() 
{
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<int>> fig(n, vector<int>(n, 0));
    int total = 0;
    for (int i = 0; i < k; i++) 
    {
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        fig[x][y] += z;
        total += z;
        fig[y][x] += z;
    }

    int sz = 1 << n;
    vector<int> nums(sz, 0);
    for (int s = 0; s < sz; s++)
    {
        for (int i = 0; i < n; i++) 
        {
            if (s & (1 << i)) 
            {
                for (int j = i + 1; j < n; j++) 
                {
                    if (s & (1 << j)) nums[s] += fig[i][j];
                }
            }
        }
    }

    vector<int> dp(sz, 0);
    for (int i = 0; i < sz; i++)
    {
        for (int s = i; s; s = (s - 1) & i) 
        {
            int cnt = bitset<32>(s).count();
            if (cnt <= m) dp[i] = max(dp[i], dp[i ^ s] + nums[s]);
        }
    }

    cout << total - dp[sz - 1] << endl;
    return 0;
}